/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server.managerServer.executors;

import protocol.Executor;
import protocol.Message;
import protocol.MessageError;
import protocol.MessageStopRep;
import protocol.MessageStopReq;
import protocol.ThreadWorker;
import server.Poll;
import server.managerServer.ServerWorker;

public class ExecutorStop extends Executor {

    MessageStopReq msg;

    public ExecutorStop(Message _msg) {
        super(_msg);
        msg = (MessageStopReq) _msg;
    }

    @Override
    public void doWork(ThreadWorker worker) {
        ServerWorker serverWorker = (ServerWorker) worker;
        long pollId = msg.getPollId();

        if (!serverWorker.stopPoll(pollId)) {
            serverWorker.sendMessage(new MessageError());
            return;
        }
        serverWorker.sendMessage(new MessageStopRep(pollId));

    }
}